package com.xt.tea.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xt.tea.constant.ApiConstant;
import com.xt.tea.entity.bo.RequestResult;
import com.xt.tea.entity.domain.Tea;
import com.xt.tea.entity.vo.Condition;
import com.xt.tea.service.TeaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("茶叶相关")
@RestController
@RequestMapping(ApiConstant.API_V1+"tea")
@AllArgsConstructor
public class TeaController {
    private final TeaService teaService;

    @ApiOperation("分页获取茶叶")
    @PostMapping("/getTea")
    public RequestResult<IPage<Tea>> getTea(@RequestBody Condition<Tea> condition){
        return RequestResult.success(teaService.getTea(condition));
    }

    @ApiOperation("获取所有茶叶")
    @GetMapping("/getAllTea")
    public RequestResult<List<Tea>> getAllTea(){
        return RequestResult.success(teaService.getAllTea());
    }

    @ApiOperation("新增茶叶")
    @PostMapping("/addTea")
    public RequestResult<Integer> addTea(@RequestBody Tea teaVo){
        return RequestResult.success(teaService.addTea(teaVo));
    }
    //修改
    @ApiOperation("更新茶叶")
    @PutMapping("/updateTea")
    public RequestResult<Tea> updateTea(@RequestBody Tea teaVo){
        return RequestResult.success(teaService.updateTea(teaVo));
    }
    //停用
    @ApiOperation("起停用茶叶")
    @GetMapping("/updateTeaStatus")
    public RequestResult<Tea> updateTeaStatus(Integer id){
        return RequestResult.success(teaService.updateTeaStatus(id));
    }
    //删除
    @ApiOperation("删除茶叶")
    @GetMapping ("/deleteTea")
    public RequestResult<Integer> deleteTea(Integer id){
        return RequestResult.success(teaService.deleteTea(id));
    }
}
